import Fly from 'flyio/dist/npm/wx'

let fly = new Fly()
// var backPath = 'http://172.16.34.89:8080/studygo'
let tikuPath = 'http://203.195.239.100:10086/tiku/api/v1'
let poolId = '4468c74d-759e-4d78-8c43-e1c5405f193b'
let token = '06e599f3-78db-4c71-b4fa-2b496beab1f6'

export async function queryPapersById (paperId, deep) {
  console.log(tikuPath + '/queryCollection')
  const res = await fly.post(tikuPath + '/queryCollection', {
    poolId: poolId,
    token: token,
    querry: {
      operator: '==',
      argument1: 'paperId',
      argument2: paperId
    },
    random: false,
    deep: deep,
    ordering: {
      sorttype: 'desc',
      field: 'create_time'
    },
    pagination: {
      page: 1,
      size: 10,
      total: 0
    }
  }, {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  })
  return res
}

export async function queryPapersByTags (tags, deep) {
  const res = await fly.post(tikuPath + '/queryCollection', {
    poolId: poolId,
    token: token,
    querry: {
      operator: 'contains',
      argument1: 'tags',
      argument2: tags
    },
    random: false,
    deep: deep,
    ordering: {
      sorttype: 'desc',
      field: 'create_time'
    },
    pagination: {
      page: 1,
      size: 10,
      total: 0
    }
  }, {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  })
  return res
}

export async function queryProbems (problemId, deep) {
  const res = fly.post(tikuPath + '/queryCollection', {
    poolId: poolId,
    token: token,
    querry: {
      operator: '==',
      argument1: 'problemId',
      argument2: problemId
    },
    random: false,
    deep: deep,
    ordering: {
      sorttype: 'desc',
      field: 'create_time'
    },
    pagination: {
      page: 1,
      size: 10,
      total: 0
    }
  }, {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  })
  return res
}

export async function addErrorProblem (problemId, unionid) {
  const res = fly.put(tikuPath + '/problemStatus', {
    poolId: poolId,
    token: token,
    problemId: problemId,
    unionid: unionid,
    status: '错题'
  }, {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  })
  return res
}

export async function addCollection (problemIds, tags) {
  const res = fly.post(tikuPath + '/queryCollection', {
    poolId: poolId,
    token: token,
    title: '试卷标题',
    problemIds: problemIds,
    tags: tags
  }, {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  })
  return res
}

export async function addUserInfo (grade, unionid) {
  const res = fly.post(tikuPath + '/userInfo', {
    unionid: unionid,
    grade: grade,
    poolId: poolId,
    token: token
  }, {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  })
  return res
}
